﻿@model Jb.Web.ViewModels.CompanyViewModel
@using Jb.Web.Utility;
@using Jb.Common.Extensions;

@{
    String pageTitle = "Edit Company Profile";
    if (Model != null && Model.ID == 0)
    {
        pageTitle = "Add New Company Profile";
    }
    ViewBag.Title = Html.GetPageTitle(pageTitle);
    bool _HasSaved = ViewData[AppConstants.ViewDataKeys.SAVED] == null ? false : Jb.Common.DB.NullHandler.GetBoolean(ViewData[AppConstants.ViewDataKeys.SAVED]);
    ViewData[AppConstants.ViewDataKeys.SELECTED_MENU] = EmployerMenu.CompanyProfile;
}

<div class="jb-page-heading">
    <div class="float-left">
        <h1>@pageTitle</h1>
        <div>Enter necessary information and then click the Save button.</div>
    </div>
    @if (!Model.Name.IsNullOrEmpty() && Model.Name != AppConstants.ValueOf.UNKNOWN) {
    <div class="float-right"><a class="btn btn-primary" href="/@(Model.Url)" target="_blank">Preview</a></div>
    }
    <div class="clearfix"></div>
</div>

<div class="jb-page-content">
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    if (Model == null)
    {
        @: @Html.WarningMessageBox("Sorry! Requested Company was not found for edit.")
    }
    else
    {
        if (Model.Name == AppConstants.ValueOf.UNKNOWN){
            Model.Name = String.Empty;
        }
        
        if (_HasSaved) {
            @Html.SuccessMessageBox(String.Format("Congratulations! Company profile of {0} saved successfully", Model.Name))
        }
        else if (ViewData[AppConstants.ViewDataKeys.SAVED] != null && !_HasSaved)
        {
            @Html.WarningMessageBox("Sorry! we could not save your company profile information.")
        }
		@Html.HiddenFor(model => model.ID)
		<div class="editor-label">
			@Html.LabelFor(model => model.Name)
            <div class="jb-label-hint">Enter the exact name of your company. Remember, this will be searchable in Job Search.</div>
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.Name, new { data_toggle = "popover", data_placement = "right", data_content = "Vivamus sagittis lacus vel augue laoreet rutrum faucibus.", title = "", data_original_title = "Popover on right" })
			@Html.ValidationMessageFor(model => model.Name)            
		</div>
    
        String logoUrl = ImageManager.GetCompanyLogoUrl(Model.LogoFile, Model.ID);
        //String jsOnClick = String.Format("ShowCenteredPopUp('{0}', 'UploadImage', 1152, 600, true);", Url.Action("List", "CompanyLogo", new { ID = Model.ID }));
        String jsOnClick = "ShowPhotoEditDialog();";
        String altText = Model.LogoFile.IsNullOrEmpty() ? "Add New Logo" : "Change Logo";
		<div class="editor-field">
            @Html.HiddenFor(model => model.LogoFile)
            <a href="javascript:void(0);" onclick="@jsOnClick">Manage Company Logo</a>
            <ul class="thumbnails">
                <li class="span4__" style="width:auto; margin:5px 0px 0px 0px;">
                    <a href="javascript:void(0);" class="thumbnail" onclick="@jsOnClick">
                        <img id="imgCompanyLogo" src="@logoUrl" alt="@altText" title="@altText" />
                    </a>
                </li>
            </ul>
		</div>
    
        <div class="editor-label">
			@Html.LabelFor(model => model.IndustryTypeID)
		</div>
		<div class="editor-field">
			@Html.DropDownListFor(model => model.IndustryTypeID, BindSelectList.IndustryTypes())
			@Html.ValidationMessageFor(model => model.IndustryTypeID)
		</div>
        <div class="editor-label">
			@Html.LabelFor(model => model.Description)
            <div class="jb-label-hint">
                A brief description of your company, this will be displayed to the Job Seekers.<br />
                If you want to create paragraph in your Company Description then, hit the "Enter" button of your keyboard to start a new line, then start typing a new paragraph.
            </div>
		</div>
		<div class="editor-field">
			@Html.TextAreaFor(model => model.Description, new { @class = "jb-long-text" })
			@Html.ValidationMessageFor(model => model.Description)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.Slogan)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.Slogan)
			@Html.ValidationMessageFor(model => model.Slogan)
		</div>
        
        <div class="jb-group-title">
            <a href="javascript:void(0);" data-toggle="collapse" data-target="#divAddress">
                <i id="iAddressToggle" class="icon-minus-sign"></i>Company Address
            </a>
        </div>
        <div id="divAddress" class="collapse in">
        @Html.EditorFor(model => model.Address)
        </div>
    
        <!--Modal Popup Section Start-->
        <div id="divPhotoEditModal">
            <iframe id="iframeImageList" scrolling="no" frameborder="0" src=""></iframe>
        </div>
	    
        <div class="jb-button-container">
			<button class="btn btn-primary" type="submit" data-loading-text="Saving..."><i class="icon-hdd icon-white"></i> Save</button> 
			@Html.PrivateLink("Cancel", "Dashboard", "Account", new { @class = "btn" })
		</div>
    }
}
</div>

@section PageHeadSection
{
    <link href="@Url.Content("~/Content/themes/jb-ui/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .ui-corner-all, .ui-corner-bottom, .ui-corner-left, .ui-corner-bl {border-bottom-left-radius: 0px;}
        .ui-corner-all, .ui-corner-bottom, .ui-corner-right, .ui-corner-br { border-bottom-right-radius: 0px;}
        #divPhotoEditModal{width:990px; height:560px; padding:0px;}
        #iframeImageList{width:100%;}
    </style>
}

@section JavaScriptPlaceHolder
{
@Html.JavaScript("jquery.validate.min.js", Url)
@Html.JavaScript("jquery.validate.unobtrusive.min.js", Url)
@Html.JavaScript("jquery-ui-1.8.11.min.js", Url)
@Html.Partial("_DatePicker")

<script language="javascript" type="text/javascript">
    var _PhotoDialog = null;
    $(document).ready(function () {
        _PhotoDialog = $('#divPhotoEditModal').dialog({
            autoOpen: false,
            title: 'Company Logo',
            modal: true,
            width: $('#divPhotoEditModal').width(),
            height: $('#divPhotoEditModal').height()
        });
        $('#divAddress').on('show', function () { $('#iAddressToggle').removeClass('icon-plus-sign').addClass('icon-minus-sign'); })
                        .on('hide', function () { $('#iAddressToggle').removeClass('icon-minus-sign').addClass('icon-plus-sign'); });
    });
    function AdjustiFrameHeight(height) {
        $('#iframeImageList').height(height);
    }
    function ChildHideLoading() {
        HideLoadingAnimation();
    }
    function SetLogo(logoUrl) {
        $('#imgCompanyLogo').attr('src', logoUrl);
        var parts = logoUrl.split('/');
        $('#PhotoFile').val(parts[parts.length - 1]);
    }
    function ShowPhotoEditDialog() {
        $(_PhotoDialog).dialog('open');
        var iFrame = $(_PhotoDialog).find('iframe');
        if ($(iFrame).attr('src').length == 0) {
            $(iFrame).attr('src', '@Url.PrivateUrl("LogoList/" + Model.ID, "Company")');
            ShowLoadingAnimation(false);
        }
    }   
</script>
}

